from rest_framework import serializers

from search.models import Record, Car


class CarSimpleSerializer(serializers.ModelSerializer):

    class Meta:
        model = Car
        fields = ('carno', 'owner')


class RecordSerializer(serializers.ModelSerializer):
    car = serializers.SerializerMethodField()
    makedate = serializers.SerializerMethodField()

    @staticmethod
    def get_makedate(record):
        return record.makedate.strftime('%Y年%m月%d日 %H:%M')

    @staticmethod
    def get_car(record):
        return CarSimpleSerializer(record.car).data

    class Meta:
        model = Record
        exclude = ('is_deleted', 'deleted_time', 'updated_time')